package com.campuscarbooking.api.service.impl;

import com.campuscarbooking.api.annotation.LogExecutionTime;
import com.campuscarbooking.api.annotation.LogMethod;
import com.campuscarbooking.api.config.RabbitMQConfig;
import com.campuscarbooking.api.dto.message.ReservationNotificationMessage;
import com.campuscarbooking.api.dto.message.ScheduleUpdateMessage;
import com.campuscarbooking.api.service.MessageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

/**
 * Implementation of MessageService using RabbitMQ
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class RabbitMQMessageServiceImpl implements MessageService {

    private final RabbitTemplate rabbitTemplate;

    @Override
    @LogMethod(value = "发送预约通知消息", logParams = true)
    @LogExecutionTime("发送预约通知消息")
    public void sendReservationNotification(ReservationNotificationMessage message) {
        log.info("Sending reservation notification message: {}", message);
        rabbitTemplate.convertAndSend(
                RabbitMQConfig.BOOKING_EXCHANGE,
                RabbitMQConfig.RESERVATION_NOTIFICATION_ROUTING_KEY,
                message
        );
        log.info("Reservation notification message sent successfully");
    }

    @Override
    @LogMethod(value = "发送班车时刻表更新消息", logParams = true)
    @LogExecutionTime("发送班车时刻表更新消息")
    public void sendScheduleUpdate(ScheduleUpdateMessage message) {
        log.info("Sending schedule update message: {}", message);
        rabbitTemplate.convertAndSend(
                RabbitMQConfig.BOOKING_EXCHANGE,
                RabbitMQConfig.SCHEDULE_UPDATE_ROUTING_KEY,
                message
        );
        log.info("Schedule update message sent successfully");
    }
} 